<?php

if(!$_POST['type'])
	exit;
if($_POST['type']=='user'){
	include '../class/connect.inc.php';
	$dest=$_POST['username'];
	$sql='select id from user where user="'.$dest.'"';
	$re=$mysqli->query($sql);
	$row=$re->fetch_assoc();
}else{
	$row=false;
	$dest=$_POST['pass'];
}

if($row)
	echo 1;		//用户存在，$_POST['type']为password时，忽略这项
else{
	$l=strlen($dest);
	if($l>5&&$l<21){
		$pattern='/\W/';
		if(preg_match($pattern,$dest))
			echo 2;		//有非字出现
		else
			echo 0;		//可以使用
	}else
		echo 3;	//不满足长度
}

if($sql)
	$mysqli->close();
